<?php
header('Content-Type: application/json; charset=utf-8');
$dbConfig = include('db_config.php');
$dsn = "mysql:host=" . $dbConfig['host'] . ";dbname=" . $dbConfig['dbname'] . ";charset=" . $dbConfig['charset'];
$pdo = new PDO($dsn, $dbConfig['username'], $dbConfig['password']);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

// 获取上传者用户的 ID
$userId = isset($_GET['user_id']) ? $_GET['user_id'] : null;

if ($userId === null) {
    die(json_encode(['status' => 'error', 'message' => '上传者参数缺失'], JSON_UNESCAPED_UNICODE));
}

// 验证用户 ID 是否合法
$stmtCheckUser = $pdo->prepare("SELECT id FROM mi_users WHERE id = ?");
$stmtCheckUser->execute([$userId]);
$userExists = $stmtCheckUser->fetchColumn();

if (!$userExists) {
    die(json_encode(['status' => 'error', 'message' => '用户不存在'], JSON_UNESCAPED_UNICODE));
}

// 查询上传文件信息，返回所有字段
$stmt = $pdo->prepare("SELECT * FROM mi_file WHERE 上传者用户的id = ?");
$stmt->execute([$userId]);
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);

echo json_encode(['status' => 'success','message' => '成功', 'data' => $results], JSON_UNESCAPED_UNICODE);
?>